﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using log4net;

using WeatherReport.Interfaces;
using WeatherReport.Services;

namespace WeatherReport.ViewModels
{
    public class ViewModelLocator
    {
        private static readonly ViewModelLocator _instance = new ViewModelLocator();

        private readonly WeatherViewModel _weatherViewModel;
        private readonly UserSettingsViewModel _userSettingsViewModel;

        public static ViewModelLocator Current
        {
            get { return _instance; }
        }

        public WeatherViewModel WeatherViewModel
        {
            get { return _weatherViewModel; }
        }
        public UserSettingsViewModel UserSettingsViewModel
        {
            get { return _userSettingsViewModel; }
        }

        public ViewModelLocator()
        {
            IWeatherService weatherService = new GlobalWeatherServiceAdapter();

            _weatherViewModel = new WeatherViewModel(weatherService, 
                LogManager.GetLogger(typeof(WeatherViewModel)), Settings.Default);
            _weatherViewModel.Init();

            _userSettingsViewModel = new UserSettingsViewModel(weatherService,
                LogManager.GetLogger(typeof(UserSettingsViewModel)), Settings.Default);
            _userSettingsViewModel.Init();
            _userSettingsViewModel.SettingsOkayed += (sender, e) =>
                _weatherViewModel.ChangeLocation(e.Data1, e.Data2);
            _userSettingsViewModel.SettingsCancelled += (sender, e) =>
                _weatherViewModel.HideSettingsLayer();
        }
    }
}
